package 力扣日常刷题.木22一月.第14天0123;

/**
 * @author 帅小伙
 * @date 2022/1/23
 * @description  求只含有一个0的最长1的数组
 */
public class Demo52删除一个元素全为1的最长子数组 {


    public static void main(String[] args) {
        longestSubarray(new int[]{1,0,1,1,0,0,1,1,1,0,1,1,1});
    }

    public static int longestSubarray(int[] nums) {
       int l = 0,c = 0, max = 0;
        for (int r = 0; r < nums.length ; r++) {
            if(nums[r] == 0) c +=1;
            while(c > 1){
                if(nums[l] == 0) c-=1;
                l+=1;
            }
            max = Math.max(max,r-l);

        }
        return max;
    }

}
